package ricardotavares.util.arquivo;

import java.io.Serializable;
import javax.swing.JOptionPane;
import ricardotavares.util.criptografia.Encrypter;
import ricardotavares.util.criptografia.EncryptorException;

public class JavaInfo implements Serializable
{
   private String host,dataBase,userName,password,port;
   private boolean salvar;

    public JavaInfo(String host, String dataBase, String userName, String password, String port,boolean salvar) {
        this.host = host;
        this.dataBase = dataBase;
        this.userName = userName;
        this.password = password;
        this.port = port;
        this.salvar = salvar;
        encriptar();
    }

    private void encriptar() {
        try {
            dataBase = Encrypter.encriptar(dataBase);
            userName = Encrypter.encriptar(userName);
            password = Encrypter.encriptar(password);
            port = Encrypter.encriptar(port);
            host = Encrypter.encriptar(host);
        } catch (EncryptorException e) {
            JOptionPane.showMessageDialog(null, "Ops! Erro na CRIPTOGRAFIA das informações.");
        }
    }

    private String decriptar(String dado) {
        try {
            return Encrypter.decriptar(dado);
        } catch (EncryptorException e) {
            JOptionPane.showMessageDialog(null, "Ops! Erro na DESCRIPTOGRAFIA das informações.");
            return "ERRO AO DESCRIPTOGRAFA DADO";
        }
    }

    public boolean isSalvar() {
        return salvar;
    }

    public String getDataBase() {
        return decriptar(dataBase);
    }

    public String getHost() {
        return decriptar(host);
    }

    public String getPassword() {
        return decriptar(password);
    }

    public String getPort() {
        return decriptar(port);
    }

    public String getUserName() {
        return decriptar(userName);
    }
}